package com.ttsx.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ttsx.mapper.OrderItemMapper;
import com.ttsx.pojo.entity.OrderItem;
import com.ttsx.service.OrderItemService;
import com.ttsx.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author wb
 * @since 2025-03-03
 */

@Service
public class OrderItemServiceImpl extends ServiceImpl<OrderItemMapper, OrderItem> implements OrderItemService {

    @Autowired
    private ProductService productService;

    @Override
    public List<OrderItem> getListByOrderId(Long orderId) {
        LambdaQueryWrapper<OrderItem> lqw = new LambdaQueryWrapper<>();
        lqw.eq(OrderItem::getOrderId, orderId);

        List<OrderItem> orderItems = baseMapper.selectList(lqw);

        return orderItems.stream()
                .peek(item -> item.setProduct(productService.getById(item.getProductId())))
                .collect(Collectors.toList());
    }
}
